---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Mandates/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 21:28:52

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Mandates";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Mandates

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Tuesday, May 26, 2015                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. *********************************;
. **      Peace to War            *;
. *********************************;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Mandates/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 
>                 diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21
>                 diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11
>                 delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=0 ;

. while `a' < 4 { ;
  2. {;
  3. *tl2 milservice tl2_mil tl1 tl1_mil;
.  scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_OneTerm=1;
  9. scalar h_TwoTerms=1;
 10. scalar h_Parliament = 0;
 11. scalar h_CivilWar = 0;
 12. scalar h_GDPpc =  12589.35;
 13. scalar h_Growth = 3.453132;
 14. scalar h_MajorPower = 0;
 15. scalar h_Borders = 2;
 16. scalar h_Mobilization =  -.0008714 ;
 17. scalar h_Time = 5;
 18.  scalar h_Rivalry = 0;
 19. scalar h_Female = 0;
 20. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 21.  generate x_betahat1 = MG_b1*h_OneTerm
>     + MG_b2*`a'
>     + MG_b3*(h_OneTerm*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 22.  generate x_betahat2 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_TwoTerms
>     + MG_b5*(h_TwoTerms*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 23.   gen prob0=1/(1+exp(-x_betahat0));
 24. gen prob1=1/(1+exp(-x_betahat1));
 25. gen prob2=1/(1+exp(-x_betahat2));
 26.  gen diff0=prob1-prob0 ;
 27. gen diff1=prob2-prob0 ;
 28. egen probhat0=mean(prob0) ;
 29. egen probhat1=mean(prob1) ;
 30. egen probhat2=mean(prob2) ;
 31. egen diffhat0=mean(diff0) ;
 32. egen diffhat1=mean(diff1) ;
 33. generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 34.  generate x_betahat11 =   MG_b1*h_OneTerm
>     + MG_b2*`a'
>     + MG_b3*(h_OneTerm*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 35.   generate x_betahat21 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_TwoTerms
>     + MG_b5*(h_TwoTerms*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 36.   gen prob01=1/(1+exp(-x_betahat01));
 37. gen prob11=1/(1+exp(-x_betahat11));
 38. gen prob21=1/(1+exp(-x_betahat21));
 39. gen diff01=prob11-prob01 ;
 40. gen diff11=prob21-prob01 ;
 41. egen probhat01=mean(prob01) ;
 42. egen probhat11=mean(prob11) ;
 43. egen probhat21=mean(prob21) ;
 44. egen diffhat01=mean(diff01) ;
 45. egen diffhat11=mean(diff11) ;
 46. gen delta=diff01-diff0;
 47. gen delta1=diff11-diff1;
 48. egen deltahat=mean(delta);
 49. egen deltahat1=mean(delta1);
 50. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2
>          diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1
>          prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21
>          diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11
>          delta_hat delta_lo delta_hi  delta_hat1 delta_lo1 delta_hi1;
 51.     _pctile prob0, p(2.5,97.5) ;
 52.     scalar `lo0'=r(r1) ;
 53.     scalar `hi0'=r(r2) ;
 54.     _pctile prob1, p(2.5,97.5) ;
 55.     scalar `lo1'=r(r1) ;
 56.     scalar `hi1'=r(r2) ;
 57.     _pctile prob2, p(2.5,97.5) ;
 58.     scalar `lo2'=r(r1) ;
 59.     scalar `hi2'=r(r2) ;
 60.         _pctile diff0, p(2.5,97.5) ;
 61.     scalar `diff_lo0'= r(r1) ;
 62.     scalar `diff_hi0'=r(r2) ;
 63.     _pctile diff1, p(2.5,97.5) ;
 64.     scalar `diff_lo1'= r(r1) ;
 65.     scalar `diff_hi1'=r(r2) ;
 66.     scalar `prob_hat0'=probhat0 ;
 67.     scalar `prob_hat1'=probhat1 ;
 68.     scalar `prob_hat2'=probhat2 ;
 69.     scalar `diff_hat0'=diffhat0 ;
 70.     scalar `diff_hat1'=diffhat1 ;
 71.        _pctile prob01, p(2.5,97.5) ;
 72.     scalar `lo01'=r(r1) ;
 73.     scalar `hi01'=r(r2) ;
 74.     _pctile prob11, p(2.5,97.5) ;
 75.     scalar `lo11'=r(r1) ;
 76.     scalar `hi11'=r(r2) ;
 77.     _pctile prob21, p(2.5,97.5) ;
 78.     scalar `lo21'=r(r1) ;
 79.     scalar `hi21'=r(r2) ;
 80.     _pctile diff01, p(2.5,97.5) ;
 81.     scalar `diff_lo01'= r(r1) ;
 82.     scalar `diff_hi01'=r(r2) ;
 83.     _pctile diff11, p(2.5,97.5) ;
 84.     scalar `diff_lo11'= r(r1) ;
 85.     scalar `diff_hi11'=r(r2) ;
 86.     scalar `prob_hat01'=probhat01 ;
 87.     scalar `prob_hat11'=probhat11 ;
 88.     scalar `prob_hat21'=probhat21 ;
 89.     scalar `diff_hat01'=diffhat01 ;
 90.     scalar `diff_hat11'=diffhat11 ;
 91.     _pctile delta, p(2.5,97.5) ;
 92.     scalar `delta_lo'= r(r1) ;
 93.     scalar `delta_hi'=r(r2) ;
 94.     _pctile delta1, p(2.5,97.5) ;
 95.     scalar `delta_lo1'= r(r1) ;
 96.     scalar `delta_hi1'=r(r2) ;
 97.     scalar `delta_hat'=deltahat;
 98.     scalar `delta_hat1'=deltahat1;
 99.     post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
>                 (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1')
>                 (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11')  (`prob_hat21') (`lo21') (`hi21')
>                 (`diff_hat01') (`diff_lo01') (`diff_hi01') (`diff_hat11') (`diff_lo11') (`diff_hi11')
>                 (`delta_hat') (`delta_lo') (`delta_hi') (`delta_hat1') (`delta_lo1') (`delta_hi1')
> 
>     ;
100.     } ;
101.     drop    x_betahat0 x_betahat1 x_betahat2
>             prob0 prob1 prob2 
>             diff0 diff1
>             probhat0 probhat1 probhat2
>             diffhat0 diffhat1
>             x_betahat01 x_betahat11 x_betahat21
>             prob01 prob11 prob21
>             diff01 diff11
>             probhat01 probhat11 probhat21
>             diffhat01 diffhat11
>             delta deltahat delta1 deltahat1;
102.     local a=`a'+ 1 ;
103.     display "." _c ;
104.     } ;
....
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. gen ruler = _n;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         4    .0730704      .02109   .0506433   .0994481
         lo0 |         4    .0462152    .0088792   .0345499   .0549081
         hi0 |         4    .1093329    .0405738   .0711791   .1633059
   prob_hat1 |         4    .0300759    .0068388   .0239521   .0393584
         lo1 |         4    .0101419    .0042131   .0049957   .0140332
-------------+--------------------------------------------------------
         hi1 |         4    .0755527    .0460052   .0378847   .1390438
   prob_hat2 |         4    .0727519    .0209881   .0558419   .1019183
         lo2 |         4    .0162859    .0073769   .0069875   .0242802
         hi2 |         4    .2133184    .1326819   .1171149   .4013993
   diff_hat0 |         4   -.0429945    .0143833  -.0600898  -.0266912
-------------+--------------------------------------------------------
    diff_lo0 |         4   -.0831047    .0391639  -.1350422  -.0467898
    diff_hi0 |         4    .0064074     .027048  -.0148911   .0451472
   diff_hat1 |         4   -.0003185    .0049461  -.0050568   .0051986
    diff_lo1 |         4    -.069009    .0403751  -.1226849  -.0337977
    diff_hi1 |         4    .1392464    .1137178   .0521028   .3017483
-------------+--------------------------------------------------------
  prob_hat01 |         4    .0730704      .02109   .0506433   .0994481
        lo01 |         4    .0462152    .0088792   .0345499   .0549081
        hi01 |         4    .1093329    .0405738   .0711791   .1633059
  prob_hat11 |         4    .0300759    .0068388   .0239521   .0393584
        lo11 |         4    .0101419    .0042131   .0049957   .0140332
-------------+--------------------------------------------------------
        hi11 |         4    .0755527    .0460052   .0378847   .1390438
  prob_hat21 |         4    .0727519    .0209881   .0558419   .1019183
        lo21 |         4    .0162859    .0073769   .0069875   .0242802
        hi21 |         4    .2133184    .1326819   .1171149   .4013993
  diff_hat01 |         4   -.0429945    .0143833  -.0600898  -.0266912
-------------+--------------------------------------------------------
   diff_lo01 |         4   -.0831047    .0391639  -.1350422  -.0467898
   diff_hi01 |         4    .0064074     .027048  -.0148911   .0451472
  diff_hat11 |         4   -.0003185    .0049461  -.0050568   .0051986
   diff_lo11 |         4    -.069009    .0403751  -.1226849  -.0337977
   diff_hi11 |         4    .1392464    .1137178   .0521028   .3017483
-------------+--------------------------------------------------------
   delta_hat |         4           0           0          0          0
    delta_lo |         4           0           0          0          0
    delta_hi |         4           0           0          0          0
  delta_hat1 |         4           0           0          0          0
   delta_lo1 |         4           0           0          0          0
-------------+--------------------------------------------------------
   delta_hi1 |         4           0           0          0          0
       ruler |         4         2.5    1.290994          1          4

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Mandates/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 21:28:52
---------------------------------------------------------------------------------------------------------------------------
